package com.sj.uabrowser.mvp.menu.view.act;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.sj.uabrowser.R;
import com.sj.uabrowser.app.CallOtherOpeanFile;
import com.sj.uabrowser.app.StatusBarUtil;
import com.sj.uabrowser.framework.BaseActivity;
import com.sj.uabrowser.framework.BasePresenter;
import com.sj.uabrowser.mvp.menu.service.DownloadService;

import java.io.File;

import butterknife.BindView;
import butterknife.OnClick;

public class EditFileNameAct extends BaseActivity {

    String downloadPath = DownloadService.DOWNLOAD_PATH;

    @BindView(R.id.tvEdit)
    TextView tvEdit;
    @BindView(R.id.et_download_filename)
    EditText etDownloadFilename;
    @BindView(R.id.tv_download_path)
    TextView tvDownloadPath;

    @Override
    public BasePresenter createPresenter() {
        return null;
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_edit_file_name;
    }

    @Override
    public void setView() {
        StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, null);
        setTopTitle("编辑文件");
        tvEdit.setText("确定");
        String filename = getIntent().getStringExtra("filename");
        etDownloadFilename.setText(filename);
        tvDownloadPath.setText(downloadPath);


    }

    @Override
    public void setData() {

    }

    @OnClick({R.id.tvEdit, R.id.tv_download_path})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvEdit:
                startIconAnim(view);
                String filename = etDownloadFilename.getText().toString().trim();
                if (TextUtils.isEmpty(filename)) {
                    showToast("文件名不能为空！");
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra("filename", filename);
                setResult(0, intent);
                finish();
                break;
            case R.id.tv_download_path:
//                File file = new File(downloadPath);
//                if(file.exists()){
//                    new CallOtherOpeanFile().openFile(this,file);
//                    Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT);
//                    Uri uri = Uri.parse(downloadPath);
//                    Logger.e("downloadPath:"+downloadPath);
////                            Uri.fromFile(file);
//                    intent1.setDataAndType(uri, "*/*");
//                    startActivity(Intent.createChooser(intent1, "Open folder"));
//                }

                break;
        }
    }

}
